//
// Created by vcq on 21/2/25.
//

#pragma once

#include "dbng.hpp"

struct teachgoal {
    int id;
    string name;
    int _require_id;
    int _syllabus_id;
    double per;
    string note;
};
REFLECTION(teachgoal, id, name, _require_id, _syllabus_id, per, note)

json MGetTeachGoal(basic_string_view<char> id,
                   basic_string_view<char> _require_id,
                   basic_string_view<char> _syllabus_id) {
    string sql = "select * from `teachgoal` where 1=1 ";
    if (!id.empty()) {
        sql += " and id =";
        sql += id;
    }
    if (!_require_id.empty()) {
        sql += " and _require_id =";
        sql += _require_id;
    }
    if (!_syllabus_id.empty()) {
        sql += " and _syllabus_id =";
        sql += _syllabus_id;
    }
    Dao dao;
    nlohmann::json article_list, ret, item;
    auto v = dao.query<teachgoal>(sql);
    for (auto &o : v) {
        item["id"] = o.id;
        item["name"] = o.name;
        item["note"] = o.note;
        item["_require_id"] = o._require_id;
        item["_syllabus_id"] = o._syllabus_id;
        item["per"] = o.per;
        item["note"] = o.note;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}

void MAddTeachGoal(const struct teachgoal &teachgoal1) {
    Dao dao;
    dao.update_object(teachgoal1);
}

void MDeleteTeachGoal(basic_string_view<char> id) {
    MDeleteAll("teachgoal", id);
}